/*
 *@Author: 张楚
 *@Date: 2021-08-03 15:25:22
 *@Description: 搜索框2
*/
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:totaldemo/getx/getx_demo/getx_demo_controller.dart';

class SearchPage2 extends StatefulWidget {
  const SearchPage2({Key key}) : super(key: key);

  @override
  _SearchPage2State createState() => _SearchPage2State();
}

class _SearchPage2State extends State<SearchPage2> {
  Getxcontroller _c = Get.put(Getxcontroller());
  @override
  void initState() {
    // TODO: implement initState
    super.initState();

    ///每次
    ever(_c.keywords, (String value) {
      print('每次都会执行 $value');
    });

    ///只会执行第一次
    once(_c.keywords, (String value) {
      print('只会执行一次 $value');
    });

    ///参数一：绑定数据
    ///参数二：延时执行方法
    ///参数三：时间
    debounce(_c.keywords, (String value) {
      print('debounce 执行 ${value}');
    }, time: Duration(seconds: 1));
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('搜索框2'),
      ),
      body: Column(
        children: [
          TextField(
            onChanged: (String value) {
              Get.find<Getxcontroller>().onchange(value);
            },
          )
        ],
      ),
    );
  }
}
